<?php

namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class UserLevel extends Model
{
    protected $table = 'user_Level';
    public $timestamps = false;
    protected $primaryKey = 'user_id';

    /**
     * 添加一个账号等级
     * @param array $data
     * @return bool
     */
    public function addLevelItem(array $data)
    {
        $data = [
            "name" => "铜牌会员",
            "amount" => "10000.00",
            "discount" => '98',
            "description" => '铜牌会员'
        ];
        $this->name = $data['name'];
        $this->amount = $data['amount'];
        $this->discount = $data['discount'];
        $this->description = $data['description'];
        if ($this->save()) {
            return $this->toArray();
        }

        return false;
    }


    /**
     * 编辑一个账号等级
     * @access public
     * @param array $data 外部数据
     * @return array|false
     */
    public function setLevelItem(array $data)
    {
        $ds = [
            "user_level_id" => '9',
            "name" => '铜牌会员',
            "amount" => '999.99',
            "discount" => '98',
            "description" => '铜牌会员'
        ];
        $res = user_Level::where('user_level_id',9)->update($ds);
        if ($res){
            return true;
        }
        return false;
    }

    /**
     * 获取一个账号
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function getLevelItem(array $data)
    {

        $res = user_Level::where('user_level_id',5)->first()->toArray();
        if ($res){
            return $res;
        }

    }
    /**
     * 获取账号等级列表
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function getLevelList(array $data)
    {
        // 实际查询
        $res = user_Level::select()->limit('10');

        return json_encode($res);
    }

    /**
     * 批量删除账号等级
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function delAddressList(array $data)
    {
        $user_level_id = [21,22,23,24,25,26];
        $res = user_Level::where('user_level_id','$user_level_id')->delete();
        if ($res){
            return $res;
        }

    }
}
